2018年/8月/1日。
到今天为止,学习ABAP大概快一个月了,我知道一个月,对于任何一门计算机语言来说,都只能说才了解,更何况是在自学,没有视频的情况下。ABAP语言相对其他语言来说,较为封闭,因为它只能在SAP系统里才能编写实现,而SAP系统对于个体户来说,安装太不现实。应该说几乎所有的ABAP开发人员都是在项目上学习的。幸运的是,我碰巧来到一个实施SAP的项目,目前在学习ABAP开发。
今天学习的内容:
目前手上的书籍有黄佳的黄皮书和王宏的蓝皮书。书本的知识还可以,但是操作和程序都太老了。
在SMARTFORMS里添加系统字段,蓝皮书说是直接拖过去,但是在SAP750里是不可以的。方法:系统的当前日期怎么显示出来。有两步:第一:在表格接口—自定义DATE TYPE BUCHDATUM**可选的和值传递都要选,然后激活**。
二:在对应的WORD里插入字段”&SFSY-DATE&”。就可以自动显示了。
第二个知识点:
****ALV列表输出 。注意注意了:如果没有子程 序。ALV的顺序是:全局定义—–得到数据——CALL FUNCTION.
并不是说在ABAP中程序的顺序没有意义,是根据关键字来走的,像FORM —ENDFORM谁在前谁在后都无所谓,但是PERFORM的顺序就有意义了,他们谁在前谁就会先执行,那么相对应的 perform中有些变量就有值了,如果后面的程序应用到PERFORM的变量的值,如果这个时候顺序搞反了,也许会出现语法没有错误,激活也成功,就是没有结果,可能是程序的顺序出错了。**
**标准的报表ALV输出**
DATA:GT_ZTSTUDENT TYPE TABLE OF ZTSTUDENT WITH HEADER LINE.
DATA:GS_FCAT TYPE LVC_S_FCAT,
GT_FCAT TYPE LVC_T_FCAT,
GS_LAYO TYPE LVC_S_LAYO,
GS_SETS TYPE LVC_S_GLAY.
DATA: BOX(1).
*查询数据
START-OF-SELECTION.
SELECT XUEHAO XINGMING XINGBIE
INTO CORRESPONDING FIELDS OF TABLE GT_ZTSTUDENT
FROM ZTSTUDENT.
*ALV列表输出。
END-OF-SELECTION.
PERFORM FRM_LIST_OUTPUT.
FORM FRM_LIST_OUTPUT .
PERFORM FRM_BULID_LIST.
CLEAR GS_LAYO.
GS_LAYO-ZEBRA = ‘X’.
GS_LAYO-SEL_MODE = ‘X’.
GS_LAYO-NO_ROWMARK = ‘X’.
CLEAR GS_SETS.
GS_SETS-EDT_CLL_CB = ‘X’.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
I_CALLBACK_PROGRAM = ‘SY-REPID’
I_STRUCTURE_NAME = ‘程序’
IS_LAYOUT_LVC = GS_LAYO
IT_FIELDCAT_LVC = GT_FCAT
I_DEFAULT = ‘X’
I_SAVE = ‘X’
TABLES
T_OUTTAB = GT_ZTSTUDENT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM.
&———————————————————————
*& Form FRM_BULID_LIST
&———————————————————————
*& text
&———————————————————————
*& –> p1 text
*& <– p2 text
&———————————————————————
FORM FRM_BULID_LIST.
REFRESH GT_FCAT.
CLEAR GS_FCAT.
GS_FCAT-FIELDNAME = ‘BOX’.
GS_FCAT-COLTEXT = ‘选择’.
GS_FCAT-EDIT = ‘X’ .
GS_FCAT-CHECKBOX = ‘X’.
APPEND GS_FCAT TO GT_FCAT.
CLEAR GS_FCAT.
GS_FCAT-FIELDNAME = ‘xuehao’.
GS_FCAT-COLTEXT = ‘学号’.
GS_FCAT-REF_TABLE = ‘ztstudent’.
GS_FCAT-REF_FIELD = ‘xuehao’.
APPEND GS_FCAT TO GT_FCAT.
CLEAR GS_FCAT.
GS_FCAT-FIELDNAME = ‘xingming’.
GS_FCAT-COLTEXT = ‘姓名’.
GS_FCAT-REF_TABLE = ‘ztstudent’.
GS_FCAT-REF_FIELD = ‘xingming’.
APPEND GS_FCAT TO GT_FCAT.
CLEAR GS_FCAT.
GS_FCAT-FIELDNAME = ‘xingbie’.
GS_FCAT-COLTEXT = ‘性别’.
GS_FCAT-REF_TABLE = ‘ztstudent’.
GS_FCAT-REF_FIELD = ‘xingbie’.
APPEND GS_FCAT TO GT_FCAT.
ENDFORM.
最简单的ALV报表:
TYPES:BEGIN OF TY_TAB,
XUEHAO TYPE ZTSTUDENT-XUEHAO,
XINGMING TYPE ZTSTUDENT-XINGMING,
XINGBIE TYPE ZTSTUDENT-XINGBIE,
END OF TY_TAB.
DATA: GT_TAB TYPE TABLE OF TY_TAB,
GS_TAB TYPE TY_TAB.
DATA:GS_FCAT TYPE LVC_S_FCAT,
GT_FCAT TYPE LVC_T_FCAT,
GS_LAYO TYPE LVC_S_LAYO,
GS_SETS TYPE LVC_S_GLAY.
DATA: BOX(1).
*查询数据
START-OF-SELECTION.
SELECT XUEHAO XINGMING XINGBIE
INTO CORRESPONDING FIELDS OF TABLE GT_ZTSTUDENT
FROM ZTSTUDENT.
*ALV列表输出。
CLEAR GS_LAYO.
GS_LAYO-ZEBRA = ‘X’.
GS_LAYO-SEL_MODE = ‘X’.
GS_LAYO-NO_ROWMARK = ‘X’.
CLEAR GS_SETS.
GS_SETS-EDT_CLL_CB = ‘X’.
REFRESH GT_FCAT.
*ALV报表布局
CLEAR GS_FCAT.
GS_FCAT-FIELDNAME = ‘BOX’.
GS_FCAT-COLTEXT = ‘选择’.
GS_FCAT-EDIT = ‘X’ .
GS_FCAT-CHECKBOX = ‘X’.
APPEND GS_FCAT TO GT_FCAT.
*字段目录
CLEAR GS_FCAT.
GS_FCAT-FIELDNAME = ‘xuehao’.
GS_FCAT-COLTEXT = ‘学号’.
GS_FCAT-REF_TABLE = ‘ztstudent’.
GS_FCAT-REF_FIELD = ‘xuehao’.
APPEND GS_FCAT TO GT_FCAT.
CLEAR GS_FCAT.
GS_FCAT-FIELDNAME = ‘xingming’.
GS_FCAT-COLTEXT = ‘姓名’.
GS_FCAT-REF_TABLE = ‘ztstudent’.
GS_FCAT-REF_FIELD = ‘xingming’.
APPEND GS_FCAT TO GT_FCAT.
CLEAR GS_FCAT.
GS_FCAT-FIELDNAME = ‘xingbie’.
GS_FCAT-COLTEXT = ‘性别’.
GS_FCAT-REF_TABLE = ‘ztstudent’.
GS_FCAT-REF_FIELD = ‘xingbie’.
APPEND GS_FCAT TO GT_FCAT.
CALL FUNCTION 一定要放在最后*布局和字段目录的后面*
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
I_CALLBACK_PROGRAM = ‘SY-REPID’
I_STRUCTURE_NAME = ‘程序’
IS_LAYOUT_LVC = GS_LAYO
IT_FIELDCAT_LVC = GT_FCAT 只有布局和字段目录在前面有值了,J才不会出错
I_DEFAULT = ‘X’
I_SAVE = ‘X’
TABLES
T_OUTTAB = GT_ZTSTUDENT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.