ABAP Select data from SAP table V_PPHMRPLOG 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 V_PPHMRPLOG 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 V_PPHMRPLOG. 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 V_PPHMRPLOG 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_V_PPHMRPLOG TYPE STANDARD TABLE OF V_PPHMRPLOG,
      WA_V_PPHMRPLOG TYPE V_PPHMRPLOG,
      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: <V_PPHMRPLOG> TYPE V_PPHMRPLOG.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM V_PPHMRPLOG
  INTO TABLE IT_V_PPHMRPLOG.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM V_PPHMRPLOG
*  INTO TABLE @DATA(IT_V_PPHMRPLOG2).
*--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_V_PPHMRPLOG INDEX 1 INTO DATA(WA_V_PPHMRPLOG2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_V_PPHMRPLOG ASSIGNING <V_PPHMRPLOG>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<V_PPHMRPLOG>-MANDT = 1.
<V_PPHMRPLOG>-UUID = 1.
<V_PPHMRPLOG>-ITEMID = 1.
<V_PPHMRPLOG>-START_TIME = 1.
<V_PPHMRPLOG>-END_TIME = 1.
ENDLOOP.

LOOP AT IT_V_PPHMRPLOG INTO WA_V_PPHMRPLOG.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_V_PPHMRPLOG-UNAME, sy-vline,
WA_V_PPHMRPLOG-REGEN, sy-vline,
WA_V_PPHMRPLOG-COMPS, sy-vline,
WA_V_PPHMRPLOG-TRANS, sy-vline,
WA_V_PPHMRPLOG-PLMOD, sy-vline,
WA_V_PPHMRPLOG-DISST, sy-vline.
ENDLOOP. *Add any further fields from structure WA_V_PPHMRPLOG 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_V_PPHMRPLOG 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_V_PPHMRPLOG INTO WA_V_PPHMRPLOG. *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 ALPHA, internal->external for field MAX_PLNUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_V_PPHMRPLOG-MAX_PLNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_V_PPHMRPLOG-MAX_PLNUM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field MAX_BANFN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_V_PPHMRPLOG-MAX_BANFN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_V_PPHMRPLOG-MAX_BANFN.
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_V_PPHMRPLOG_STR,
MANDT TYPE STRING,
UUID TYPE STRING,
ITEMID TYPE STRING,
START_TIME TYPE STRING,
END_TIME TYPE STRING,
UNAME TYPE STRING,
REGEN TYPE STRING,
COMPS TYPE STRING,
TRANS TYPE STRING,
PLMOD TYPE STRING,
DISST TYPE STRING,
MRP_KIND TYPE STRING,
ITEM_START_TIME TYPE STRING,
TIME_OVERALL TYPE STRING,
TIME_MASTER TYPE STRING,
TIME_DOCUMENTS TYPE STRING,
TIME_CALC TYPE STRING,
TIME_UPDATE TYPE STRING,
EBAN_DEL TYPE STRING,
EBAN_INS TYPE STRING,
EBAN_UPD TYPE STRING,
PLAF_DEL TYPE STRING,
PLAF_INS TYPE STRING,
PLAF_UPD TYPE STRING,
EKET_DEL TYPE STRING,
EKET_INS TYPE STRING,
EKET_UPD TYPE STRING,
RESB_DEL TYPE STRING,
RESB_INS TYPE STRING,
RESB_UPD TYPE STRING,
DBVM_UPD TYPE STRING,
MDPS_READ TYPE STRING,
MATERIALS_READ TYPE STRING,
MATERIALS_PLANNED TYPE STRING,
MATERIALS_NOT_PLANNED TYPE STRING,
SELSTRING TYPE STRING,
ITEM_END_TIME TYPE STRING,
TIME_PURREQ_UPD TYPE STRING,
TIME_PLAF_INS TYPE STRING,
TIME_PLAF_DEL TYPE STRING,
TIME_SCHEDL_UPD TYPE STRING,
TIME_QUMNG_UPD TYPE STRING,
TIME_DBVM_UPD TYPE STRING,
TIME_DBVMSET_UPD TYPE STRING,
PLAF_W_BOM_P_MAT TYPE STRING,
PLAF_INS_W_BOM TYPE STRING,
EKPO_UPD TYPE STRING,
NUM_PAR TYPE STRING,
MAX_PLNUM TYPE STRING,
MAX_BANFN TYPE STRING,
MAX_RSNUM TYPE STRING,
VERTR TYPE STRING,
DISPD TYPE STRING,
WO_AUTH TYPE STRING,
NOT_LOCKED TYPE STRING,
MRP_COMMENT TYPE STRING,
ERROR_STRING TYPE STRING,
JOBCOUNT TYPE STRING,
JOBNAME TYPE STRING,
STEPCOUNT TYPE STRING,
TIME_OVERALL_HDR TYPE STRING,END OF T_EKKO_STR. DATA: WA_V_PPHMRPLOG_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_V_PPHMRPLOG_STR-MANDT sy-vline
WA_V_PPHMRPLOG_STR-UUID sy-vline
WA_V_PPHMRPLOG_STR-ITEMID sy-vline
WA_V_PPHMRPLOG_STR-START_TIME sy-vline
WA_V_PPHMRPLOG_STR-END_TIME sy-vline
WA_V_PPHMRPLOG_STR-UNAME sy-vline
WA_V_PPHMRPLOG_STR-REGEN sy-vline
WA_V_PPHMRPLOG_STR-COMPS sy-vline
WA_V_PPHMRPLOG_STR-TRANS sy-vline
WA_V_PPHMRPLOG_STR-PLMOD sy-vline
WA_V_PPHMRPLOG_STR-DISST sy-vline
WA_V_PPHMRPLOG_STR-MRP_KIND sy-vline
WA_V_PPHMRPLOG_STR-ITEM_START_TIME sy-vline
WA_V_PPHMRPLOG_STR-TIME_OVERALL sy-vline
WA_V_PPHMRPLOG_STR-TIME_MASTER sy-vline
WA_V_PPHMRPLOG_STR-TIME_DOCUMENTS sy-vline
WA_V_PPHMRPLOG_STR-TIME_CALC sy-vline
WA_V_PPHMRPLOG_STR-TIME_UPDATE sy-vline
WA_V_PPHMRPLOG_STR-EBAN_DEL sy-vline
WA_V_PPHMRPLOG_STR-EBAN_INS sy-vline
WA_V_PPHMRPLOG_STR-EBAN_UPD sy-vline
WA_V_PPHMRPLOG_STR-PLAF_DEL sy-vline
WA_V_PPHMRPLOG_STR-PLAF_INS sy-vline
WA_V_PPHMRPLOG_STR-PLAF_UPD sy-vline
WA_V_PPHMRPLOG_STR-EKET_DEL sy-vline
WA_V_PPHMRPLOG_STR-EKET_INS sy-vline
WA_V_PPHMRPLOG_STR-EKET_UPD sy-vline
WA_V_PPHMRPLOG_STR-RESB_DEL sy-vline
WA_V_PPHMRPLOG_STR-RESB_INS sy-vline
WA_V_PPHMRPLOG_STR-RESB_UPD sy-vline
WA_V_PPHMRPLOG_STR-DBVM_UPD sy-vline
WA_V_PPHMRPLOG_STR-MDPS_READ sy-vline
WA_V_PPHMRPLOG_STR-MATERIALS_READ sy-vline
WA_V_PPHMRPLOG_STR-MATERIALS_PLANNED sy-vline
WA_V_PPHMRPLOG_STR-MATERIALS_NOT_PLANNED sy-vline
WA_V_PPHMRPLOG_STR-SELSTRING sy-vline
WA_V_PPHMRPLOG_STR-ITEM_END_TIME sy-vline
WA_V_PPHMRPLOG_STR-TIME_PURREQ_UPD sy-vline
WA_V_PPHMRPLOG_STR-TIME_PLAF_INS sy-vline
WA_V_PPHMRPLOG_STR-TIME_PLAF_DEL sy-vline
WA_V_PPHMRPLOG_STR-TIME_SCHEDL_UPD sy-vline
WA_V_PPHMRPLOG_STR-TIME_QUMNG_UPD sy-vline
WA_V_PPHMRPLOG_STR-TIME_DBVM_UPD sy-vline
WA_V_PPHMRPLOG_STR-TIME_DBVMSET_UPD sy-vline
WA_V_PPHMRPLOG_STR-PLAF_W_BOM_P_MAT sy-vline
WA_V_PPHMRPLOG_STR-PLAF_INS_W_BOM sy-vline
WA_V_PPHMRPLOG_STR-EKPO_UPD sy-vline
WA_V_PPHMRPLOG_STR-NUM_PAR sy-vline
WA_V_PPHMRPLOG_STR-MAX_PLNUM sy-vline
WA_V_PPHMRPLOG_STR-MAX_BANFN sy-vline
WA_V_PPHMRPLOG_STR-MAX_RSNUM sy-vline
WA_V_PPHMRPLOG_STR-VERTR sy-vline
WA_V_PPHMRPLOG_STR-DISPD sy-vline
WA_V_PPHMRPLOG_STR-WO_AUTH sy-vline
WA_V_PPHMRPLOG_STR-NOT_LOCKED sy-vline
WA_V_PPHMRPLOG_STR-MRP_COMMENT sy-vline
WA_V_PPHMRPLOG_STR-ERROR_STRING sy-vline
WA_V_PPHMRPLOG_STR-JOBCOUNT sy-vline
WA_V_PPHMRPLOG_STR-JOBNAME sy-vline
WA_V_PPHMRPLOG_STR-STEPCOUNT sy-vline
WA_V_PPHMRPLOG_STR-TIME_OVERALL_HDR sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.