Successfully reported this slideshow.

Zmd Constant


Published on

ABAP tips-n-tricks

  • Be the first to comment

Zmd Constant

  1. 1. ZMD_CONSTANT and ZHEADING examples ZMD_Constant table – If I had to do it again – ZSUBROUTINE should be removed, and zprogram should be name.
  2. 2. ZMD_CONSTANT and ZHEADING examples Here’s a select statement with constants select matnr matkl into table i_mara from mara where matnr in s_matnr and ( matkl = ‘80’ or Matkl = ‘80S’ ) Here’s the ZMD_CONSTANT entry: This is a sample program using ZMD_CONSTANT and ZHEADING. The ZHEADING code will follow. ZHEADING is the standard heading we use on all reports. REPORT ZMCSIMPLE no standard page heading. tables: mara, zmd_constant. data: i_zmd_constant type standard table of zmd_constant, w_zmd_constant type zmd_constant. types: begin of t_matkl, sign type zmd_constant-zsign, option type zmd_constant-zoption, low type zmd_constant-field_low, high type zmd_constant-field_high, end of t_matkl. data: i_pdt type standard table of t_matkl, w_pdt type t_matkl. types: begin of t_mara, matnr type mara-matnr, matkl type mara-matkl, end of t_mara. data: i_mara type standard table of t_mara, w_mara type t_mara. data: w_matnr type mara-matnr. constants: c_pdt(3) value 'PDT'. SELECT-OPTIONS: s_matnr for mara-matnr. START-OF-SELECTION. perform load_constant. *** Show Limit of select by range select matnr matkl into table i_mara from mara where matnr in s_matnr and
  3. 3. ZMD_CONSTANT and ZHEADING examples matkl in i_pdt. if sy-subrc <> 0. write: / 'No records found for selection'. endif. loop at i_mara into w_mara. write: / w_mara-matnr, w_mara-matkl. endloop. END-OF-SELECTION. TOP-OF-PAGE. INCLUDE zheading. uline. perform write_selections. write: /. *---------------------------------------------------------------------* * FORM load_constant * *---------------------------------------------------------------------* form load_constant. *** Select statement to pull data from zmd_constant SELECT * FROM zmd_constant INTO TABLE i_zmd_constant WHERE zprogram = c_pdt. IF sy-subrc <> 0. WRITE: text-001. ENDIF. *Puts results of the select statement above into usable format LOOP AT i_zmd_constant INTO w_zmd_constant. CASE w_zmd_constant-zstatement. WHEN c_pdt. w_pdt-sign = w_zmd_constant-zsign. w_pdt-option = w_zmd_constant-zoption. w_pdt-low = w_zmd_constant-field_low. w_pdt-high = w_zmd_constant-field_high. APPEND w_pdt to i_pdt. endcase. endloop. endform. *---------------------------------------------------------------------* * FORM write_selections * *---------------------------------------------------------------------* form write_selections. write: 'Material:'. loop at s_matnr.. write: / s_matnr-low. endloop. ZHEADING is an include program. This is the ZHEADING code: data: gv_system_INC(8) type c. data: gv_position_INC type i. DATA: GV_PAGNO_INC(6) TYPE C. quot;DEVK930068 data: w_report_syst(46) type c. quot;DEVK934952
  4. 4. ZMD_CONSTANT and ZHEADING examples ULINE. *** FORMAT PERRIGO COMPANY LINE concatenate syst-sysid syst-mandt into gv_system_INC separated by '/'. concatenate syst-repid gv_system_inc into w_report_syst separated by ' '. quot;DEVK934952 *rite: / syst-repid, gv_system_INC. quot;DEVK934952 write: / w_report_syst. quot;DEVK934952 * POS=(LINE SZ - BOTH SIDES SPACE - TITLE LNGTH) / 2 + LEFT SIDE SPACE gv_position_INC = ( sy-linsz - 36 - 15 ) / 2 + 17. write: at gv_position_INC(15) 'Perrigo Company'. * POSITION = LINE SIZE - SPACE NEEDED TO RIGHT gv_position_INC = sy-linsz - 19. write: at gv_position_INC syst-datum, syst-uzeit. *** FORMAT TITLE LINE WRITE: / SYST-UNAME. *gv_position_INC = strlen( syst-title(60) ). quot;devk939430 gv_position_INC = strlen( syst-title(70) ). quot;devk939430 * POS = (LINE SZ - BOTH SIDES SPACE - TITLE LNGTH) / 2 + LEFT SIDE SPACE gv_position_INC = ( sy-linsz - 17 - gv_position_INC ) / 2 + 8. *write: at gv_position_INC(60) syst-title. quot;devk939430 write: at gv_position_INC(70) syst-title. quot;devk939430 * POS = LINE SIZE - SPACE NEEDED TO RIGHT GV_POSITION_INC = SY-LINSZ - 12. quot;DEVK930068 gv_pagno_INC = syst-pagno. write: at gv_position_inc 'Page:', gv_pagno_INC.