ABAP Select data from SAP table /SCWM/S_LAGP_MON into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP /SCWM/S_LAGP_MON table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to /SCWM/S_LAGP_MON. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the /SCWM/S_LAGP_MON table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_/SCWM/S_LAGP_MON TYPE STANDARD TABLE OF /SCWM/S_LAGP_MON,
      WA_/SCWM/S_LAGP_MON TYPE /SCWM/S_LAGP_MON,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: </SCWM/S_LAGP_MON> TYPE /SCWM/S_LAGP_MON.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_/SCWM/S_LAGP_MON.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /SCWM/S_LAGP_MON
  INTO TABLE IT_/SCWM/S_LAGP_MON.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /SCWM/S_LAGP_MON
*  INTO TABLE @DATA(IT_/SCWM/S_LAGP_MON2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_/SCWM/S_LAGP_MON INDEX 1 INTO DATA(WA_/SCWM/S_LAGP_MON2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCWM/S_LAGP_MON ASSIGNING </SCWM/S_LAGP_MON>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCWM/S_LAGP_MON>-LGNUM = 1.
</SCWM/S_LAGP_MON>-LGPLA = 1.
</SCWM/S_LAGP_MON>-LGTYP = 1.
</SCWM/S_LAGP_MON>-LGBER = 1.
</SCWM/S_LAGP_MON>-LPTYP = 1.
ENDLOOP.

LOOP AT IT_/SCWM/S_LAGP_MON INTO WA_/SCWM/S_LAGP_MON.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCWM/S_LAGP_MON-BIN_AT, sy-vline,
WA_/SCWM/S_LAGP_MON-PLAUF, sy-vline,
WA_/SCWM/S_LAGP_MON-PLPOS, sy-vline,
WA_/SCWM/S_LAGP_MON-SKZUA, sy-vline,
WA_/SCWM/S_LAGP_MON-SKZUE, sy-vline,
WA_/SCWM/S_LAGP_MON-SKZSI, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCWM/S_LAGP_MON you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_/SCWM/S_LAGP_MON TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_/SCWM/S_LAGP_MON INTO WA_/SCWM/S_LAGP_MON. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.

*Conversion exit CUNIT, internal->external for field UNIT_W CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_LAGP_MON-UNIT_W IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_LAGP_MON-UNIT_W.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field UNIT_V CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_LAGP_MON-UNIT_V IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_LAGP_MON-UNIT_V.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPH0, internal->external for field BTANR CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_LAGP_MON-BTANR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_LAGP_MON-BTANR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field IVNUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_LAGP_MON-IVNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_LAGP_MON-IVNUM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPH0, internal->external for field REM_BIN_DEPTH CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_LAGP_MON-REM_BIN_DEPTH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_LAGP_MON-REM_BIN_DEPTH.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPH0, internal->external for field MAX_BIN_DEPTH CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_LAGP_MON-MAX_BIN_DEPTH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_LAGP_MON-MAX_BIN_DEPTH.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/SCWM/S_LAGP_MON_STR,
LGNUM TYPE STRING,
LGPLA TYPE STRING,
LGTYP TYPE STRING,
LGBER TYPE STRING,
LPTYP TYPE STRING,
BIN_AT TYPE STRING,
PLAUF TYPE STRING,
PLPOS TYPE STRING,
SKZUA TYPE STRING,
SKZUE TYPE STRING,
SKZSI TYPE STRING,
FLGSBIN TYPE STRING,
ANZLE TYPE STRING,
MAXLE TYPE STRING,
MAX_WEIGHT TYPE STRING,
UNIT_W TYPE STRING,
WEIGHT TYPE STRING,
VOLUM TYPE STRING,
MAX_VOLUME TYPE STRING,
UNIT_V TYPE STRING,
MAX_CAPA TYPE STRING,
FCAPA TYPE STRING,
KZLER TYPE STRING,
KZVOL TYPE STRING,
PTWY_DATE TYPE STRING,
MOVED_TIME TYPE STRING,
MOVED_DATE TYPE STRING,
BTANR TYPE STRING,
CLEARED_TIME TYPE STRING,
CLEARED_DATE TYPE STRING,
KZINV TYPE STRING,
IDATUM TYPE STRING,
IVNUM TYPE STRING,
IVPOS TYPE STRING,
BRAND TYPE STRING,
UNAME TYPE STRING,
CHANGED_TIME TYPE STRING,
CHANGED_DATE TYPE STRING,
VERIF TYPE STRING,
LGPLA_MAIN TYPE STRING,
AISLE TYPE STRING,
STACK TYPE STRING,
LVL_V TYPE STRING,
BINSC TYPE STRING,
DEPTH TYPE STRING,
X_CORD TYPE STRING,
Y_CORD TYPE STRING,
Z_CORD TYPE STRING,
FIXBINTYP TYPE STRING,
USER_STATUS TYPE STRING,
PSAS TYPE STRING,
ANGLE TYPE STRING,
LGBER_LGST TYPE STRING,
REC_GRP TYPE STRING,
REM_BIN_DEPTH TYPE STRING,
MAX_BIN_DEPTH TYPE STRING,
PBV_VERIF TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCWM/S_LAGP_MON_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_/SCWM/S_LAGP_MON_STR-LGNUM sy-vline
WA_/SCWM/S_LAGP_MON_STR-LGPLA sy-vline
WA_/SCWM/S_LAGP_MON_STR-LGTYP sy-vline
WA_/SCWM/S_LAGP_MON_STR-LGBER sy-vline
WA_/SCWM/S_LAGP_MON_STR-LPTYP sy-vline
WA_/SCWM/S_LAGP_MON_STR-BIN_AT sy-vline
WA_/SCWM/S_LAGP_MON_STR-PLAUF sy-vline
WA_/SCWM/S_LAGP_MON_STR-PLPOS sy-vline
WA_/SCWM/S_LAGP_MON_STR-SKZUA sy-vline
WA_/SCWM/S_LAGP_MON_STR-SKZUE sy-vline
WA_/SCWM/S_LAGP_MON_STR-SKZSI sy-vline
WA_/SCWM/S_LAGP_MON_STR-FLGSBIN sy-vline
WA_/SCWM/S_LAGP_MON_STR-ANZLE sy-vline
WA_/SCWM/S_LAGP_MON_STR-MAXLE sy-vline
WA_/SCWM/S_LAGP_MON_STR-MAX_WEIGHT sy-vline
WA_/SCWM/S_LAGP_MON_STR-UNIT_W sy-vline
WA_/SCWM/S_LAGP_MON_STR-WEIGHT sy-vline
WA_/SCWM/S_LAGP_MON_STR-VOLUM sy-vline
WA_/SCWM/S_LAGP_MON_STR-MAX_VOLUME sy-vline
WA_/SCWM/S_LAGP_MON_STR-UNIT_V sy-vline
WA_/SCWM/S_LAGP_MON_STR-MAX_CAPA sy-vline
WA_/SCWM/S_LAGP_MON_STR-FCAPA sy-vline
WA_/SCWM/S_LAGP_MON_STR-KZLER sy-vline
WA_/SCWM/S_LAGP_MON_STR-KZVOL sy-vline
WA_/SCWM/S_LAGP_MON_STR-PTWY_DATE sy-vline
WA_/SCWM/S_LAGP_MON_STR-MOVED_TIME sy-vline
WA_/SCWM/S_LAGP_MON_STR-MOVED_DATE sy-vline
WA_/SCWM/S_LAGP_MON_STR-BTANR sy-vline
WA_/SCWM/S_LAGP_MON_STR-CLEARED_TIME sy-vline
WA_/SCWM/S_LAGP_MON_STR-CLEARED_DATE sy-vline
WA_/SCWM/S_LAGP_MON_STR-KZINV sy-vline
WA_/SCWM/S_LAGP_MON_STR-IDATUM sy-vline
WA_/SCWM/S_LAGP_MON_STR-IVNUM sy-vline
WA_/SCWM/S_LAGP_MON_STR-IVPOS sy-vline
WA_/SCWM/S_LAGP_MON_STR-BRAND sy-vline
WA_/SCWM/S_LAGP_MON_STR-UNAME sy-vline
WA_/SCWM/S_LAGP_MON_STR-CHANGED_TIME sy-vline
WA_/SCWM/S_LAGP_MON_STR-CHANGED_DATE sy-vline
WA_/SCWM/S_LAGP_MON_STR-VERIF sy-vline
WA_/SCWM/S_LAGP_MON_STR-LGPLA_MAIN sy-vline
WA_/SCWM/S_LAGP_MON_STR-AISLE sy-vline
WA_/SCWM/S_LAGP_MON_STR-STACK sy-vline
WA_/SCWM/S_LAGP_MON_STR-LVL_V sy-vline
WA_/SCWM/S_LAGP_MON_STR-BINSC sy-vline
WA_/SCWM/S_LAGP_MON_STR-DEPTH sy-vline
WA_/SCWM/S_LAGP_MON_STR-X_CORD sy-vline
WA_/SCWM/S_LAGP_MON_STR-Y_CORD sy-vline
WA_/SCWM/S_LAGP_MON_STR-Z_CORD sy-vline
WA_/SCWM/S_LAGP_MON_STR-FIXBINTYP sy-vline
WA_/SCWM/S_LAGP_MON_STR-USER_STATUS sy-vline
WA_/SCWM/S_LAGP_MON_STR-PSAS sy-vline
WA_/SCWM/S_LAGP_MON_STR-ANGLE sy-vline
WA_/SCWM/S_LAGP_MON_STR-LGBER_LGST sy-vline
WA_/SCWM/S_LAGP_MON_STR-REC_GRP sy-vline
WA_/SCWM/S_LAGP_MON_STR-REM_BIN_DEPTH sy-vline
WA_/SCWM/S_LAGP_MON_STR-MAX_BIN_DEPTH sy-vline
WA_/SCWM/S_LAGP_MON_STR-PBV_VERIF sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.