ABAP Select data from SAP table ISTICKETITEMTP3_D 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 ISTICKETITEMTP3_D 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 ISTICKETITEMTP3_D. 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 ISTICKETITEMTP3_D 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_ISTICKETITEMTP3_D TYPE STANDARD TABLE OF ISTICKETITEMTP3_D,
      WA_ISTICKETITEMTP3_D TYPE ISTICKETITEMTP3_D,
      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: <ISTICKETITEMTP3_D> TYPE ISTICKETITEMTP3_D.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM ISTICKETITEMTP3_D
*  INTO TABLE @DATA(IT_ISTICKETITEMTP3_D2).
*--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_ISTICKETITEMTP3_D INDEX 1 INTO DATA(WA_ISTICKETITEMTP3_D2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_ISTICKETITEMTP3_D ASSIGNING <ISTICKETITEMTP3_D>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<ISTICKETITEMTP3_D>-NOMINATIONTICKETKEY = 1.
<ISTICKETITEMTP3_D>-NOMINATIONTICKETITEM = 1.
<ISTICKETITEMTP3_D>-NOMINATIONTICKETPURPOSE = 1.
<ISTICKETITEMTP3_D>-NOMINATIONTICKETVERSION = 1.
<ISTICKETITEMTP3_D>-NOMINATIONDOC = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_ISTICKETITEMTP3_D-NOMINATIONDOCITEM, sy-vline,
WA_ISTICKETITEMTP3_D-NOMINATIONEXTNUMBER, sy-vline,
WA_ISTICKETITEMTP3_D-NOMINATIONSCHEDULETYPE, sy-vline,
WA_ISTICKETITEMTP3_D-DEMANDMATERIAL, sy-vline,
WA_ISTICKETITEMTP3_D-NOMINATIONTYPE, sy-vline,
WA_ISTICKETITEMTP3_D-LOCATIONNAME, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ISTICKETITEMTP3_D 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_ISTICKETITEMTP3_D 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_ISTICKETITEMTP3_D INTO WA_ISTICKETITEMTP3_D. *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 NOMINATIONTICKETKEY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISTICKETITEMTP3_D-NOMINATIONTICKETKEY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTICKETITEMTP3_D-NOMINATIONTICKETKEY.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit MATN1, internal->external for field DEMANDMATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_ISTICKETITEMTP3_D-DEMANDMATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTICKETITEMTP3_D-DEMANDMATERIAL.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field SCHEDULEDMATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_ISTICKETITEMTP3_D-SCHEDULEDMATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTICKETITEMTP3_D-SCHEDULEDMATERIAL.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

*Conversion exit CUNIT, internal->external for field STOPGAUGEUNITOFMEASURE CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_ISTICKETITEMTP3_D-STOPGAUGEUNITOFMEASURE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISTICKETITEMTP3_D-STOPGAUGEUNITOFMEASURE.
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_ISTICKETITEMTP3_D_STR,
NOMINATIONTICKETKEY TYPE STRING,
NOMINATIONTICKETITEM TYPE STRING,
NOMINATIONTICKETPURPOSE TYPE STRING,
NOMINATIONTICKETVERSION TYPE STRING,
NOMINATIONDOC TYPE STRING,
NOMINATIONDOCITEM TYPE STRING,
NOMINATIONEXTNUMBER TYPE STRING,
NOMINATIONSCHEDULETYPE TYPE STRING,
DEMANDMATERIAL TYPE STRING,
NOMINATIONTYPE TYPE STRING,
LOCATIONNAME TYPE STRING,
LOCATIONID TYPE STRING,
TRANSPORTSYSTEM TYPE STRING,
TICKETCREATIONDATE TYPE STRING,
SCHEDULEDMATERIAL TYPE STRING,
SCHEDULEDQUANTITY TYPE STRING,
BASEUNIT TYPE STRING,
TICKETDOCUMENTPOSTINGDATE TYPE STRING,
TICKETSTATUSCOLORCODE TYPE STRING,
QUANTITYSTARTDATETIME TYPE STRING,
QUANTITYENDDATETIME TYPE STRING,
QUANTITYPOSTINGDATETIME TYPE STRING,
GENERALMETERNUMBER TYPE STRING,
METEROPENQUANTITY TYPE STRING,
ENDCOUNTERMETERREADING TYPE STRING,
OPENMETERDATETIME TYPE STRING,
CLOSEMETERDATETIME TYPE STRING,
STOPMETERCALCULATIONQUANTITY TYPE STRING,
STOPMETERUNITOFMEASURE TYPE STRING,
TANKSEQUENCENUMBER TYPE STRING,
STORAGEOBJECTSEGMENTNUMBER TYPE STRING,
GAUGEOPENDIPREADING TYPE STRING,
OPENTANKDIPDATETIME TYPE STRING,
GAUGECLOSEDIPREADING TYPE STRING,
CLOSETANKDIPDATETIME TYPE STRING,
CALCULATEDGAUGEQUANTITY TYPE STRING,
GAUGETIMEZONE TYPE STRING,
TICKETCREATEDBYUSER TYPE STRING,
TICKETCREATIONTIME TYPE STRING,
TICKETCHANGEDBYUSER TYPE STRING,
NOMINATIONITEMSTATUS TYPE STRING,
NOMINATIONITEMSUBSTATUS TYPE STRING,
LATESTTICKETSTATUS TYPE STRING,
TICKETCORRUPTMODE TYPE STRING,
TICKETREVERSEMODE TYPE STRING,
TICKETCORRECTIONMODE TYPE STRING,
TYPEOFMOVEMENT TYPE STRING,
QUANTITYISMARKED TYPE STRING,
METERISMARKED TYPE STRING,
GAUGEISMARKED TYPE STRING,
TICKETNUMBER TYPE STRING,
TICKETEXTERNALNUMBER TYPE STRING,
NOMINATIONTICKETTYPE TYPE STRING,
VEHICLEID TYPE STRING,
TICKETCHANGEDDATE TYPE STRING,
NOMINATIONEVENTDATE TYPE STRING,
STOPGAUGEUNITOFMEASURE TYPE STRING,
BULKSHIPMENTTYPE TYPE STRING,
ORIGINPLANT TYPE STRING,
ORIGINSTORAGELOCATION TYPE STRING,
DESTINATIONPLANT TYPE STRING,
DESTINATIONSTORAGELOCATION TYPE STRING,
HASACTIVEENTITY TYPE STRING,
DRAFTENTITYCREATIONDATETIME TYPE STRING,
DRAFTENTITYLASTCHANGEDATETIME TYPE STRING,
DRAFTADMINISTRATIVEDATAUUID TYPE STRING,
DRAFTENTITYCONSISTENCYSTATUS TYPE STRING,
DRAFTENTITYOPERATIONCODE TYPE STRING,
ISACTIVEENTITY TYPE STRING,END OF T_EKKO_STR. DATA: WA_ISTICKETITEMTP3_D_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_ISTICKETITEMTP3_D_STR-NOMINATIONTICKETKEY sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONTICKETITEM sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONTICKETPURPOSE sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONTICKETVERSION sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONDOC sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONDOCITEM sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONEXTNUMBER sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONSCHEDULETYPE sy-vline
WA_ISTICKETITEMTP3_D_STR-DEMANDMATERIAL sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONTYPE sy-vline
WA_ISTICKETITEMTP3_D_STR-LOCATIONNAME sy-vline
WA_ISTICKETITEMTP3_D_STR-LOCATIONID sy-vline
WA_ISTICKETITEMTP3_D_STR-TRANSPORTSYSTEM sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETCREATIONDATE sy-vline
WA_ISTICKETITEMTP3_D_STR-SCHEDULEDMATERIAL sy-vline
WA_ISTICKETITEMTP3_D_STR-SCHEDULEDQUANTITY sy-vline
WA_ISTICKETITEMTP3_D_STR-BASEUNIT sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETDOCUMENTPOSTINGDATE sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETSTATUSCOLORCODE sy-vline
WA_ISTICKETITEMTP3_D_STR-QUANTITYSTARTDATETIME sy-vline
WA_ISTICKETITEMTP3_D_STR-QUANTITYENDDATETIME sy-vline
WA_ISTICKETITEMTP3_D_STR-QUANTITYPOSTINGDATETIME sy-vline
WA_ISTICKETITEMTP3_D_STR-GENERALMETERNUMBER sy-vline
WA_ISTICKETITEMTP3_D_STR-METEROPENQUANTITY sy-vline
WA_ISTICKETITEMTP3_D_STR-ENDCOUNTERMETERREADING sy-vline
WA_ISTICKETITEMTP3_D_STR-OPENMETERDATETIME sy-vline
WA_ISTICKETITEMTP3_D_STR-CLOSEMETERDATETIME sy-vline
WA_ISTICKETITEMTP3_D_STR-STOPMETERCALCULATIONQUANTITY sy-vline
WA_ISTICKETITEMTP3_D_STR-STOPMETERUNITOFMEASURE sy-vline
WA_ISTICKETITEMTP3_D_STR-TANKSEQUENCENUMBER sy-vline
WA_ISTICKETITEMTP3_D_STR-STORAGEOBJECTSEGMENTNUMBER sy-vline
WA_ISTICKETITEMTP3_D_STR-GAUGEOPENDIPREADING sy-vline
WA_ISTICKETITEMTP3_D_STR-OPENTANKDIPDATETIME sy-vline
WA_ISTICKETITEMTP3_D_STR-GAUGECLOSEDIPREADING sy-vline
WA_ISTICKETITEMTP3_D_STR-CLOSETANKDIPDATETIME sy-vline
WA_ISTICKETITEMTP3_D_STR-CALCULATEDGAUGEQUANTITY sy-vline
WA_ISTICKETITEMTP3_D_STR-GAUGETIMEZONE sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETCREATEDBYUSER sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETCREATIONTIME sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETCHANGEDBYUSER sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONITEMSTATUS sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONITEMSUBSTATUS sy-vline
WA_ISTICKETITEMTP3_D_STR-LATESTTICKETSTATUS sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETCORRUPTMODE sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETREVERSEMODE sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETCORRECTIONMODE sy-vline
WA_ISTICKETITEMTP3_D_STR-TYPEOFMOVEMENT sy-vline
WA_ISTICKETITEMTP3_D_STR-QUANTITYISMARKED sy-vline
WA_ISTICKETITEMTP3_D_STR-METERISMARKED sy-vline
WA_ISTICKETITEMTP3_D_STR-GAUGEISMARKED sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETNUMBER sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETEXTERNALNUMBER sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONTICKETTYPE sy-vline
WA_ISTICKETITEMTP3_D_STR-VEHICLEID sy-vline
WA_ISTICKETITEMTP3_D_STR-TICKETCHANGEDDATE sy-vline
WA_ISTICKETITEMTP3_D_STR-NOMINATIONEVENTDATE sy-vline
WA_ISTICKETITEMTP3_D_STR-STOPGAUGEUNITOFMEASURE sy-vline
WA_ISTICKETITEMTP3_D_STR-BULKSHIPMENTTYPE sy-vline
WA_ISTICKETITEMTP3_D_STR-ORIGINPLANT sy-vline
WA_ISTICKETITEMTP3_D_STR-ORIGINSTORAGELOCATION sy-vline
WA_ISTICKETITEMTP3_D_STR-DESTINATIONPLANT sy-vline
WA_ISTICKETITEMTP3_D_STR-DESTINATIONSTORAGELOCATION sy-vline
WA_ISTICKETITEMTP3_D_STR-HASACTIVEENTITY sy-vline
WA_ISTICKETITEMTP3_D_STR-DRAFTENTITYCREATIONDATETIME sy-vline
WA_ISTICKETITEMTP3_D_STR-DRAFTENTITYLASTCHANGEDATETIME sy-vline
WA_ISTICKETITEMTP3_D_STR-DRAFTADMINISTRATIVEDATAUUID sy-vline
WA_ISTICKETITEMTP3_D_STR-DRAFTENTITYCONSISTENCYSTATUS sy-vline
WA_ISTICKETITEMTP3_D_STR-DRAFTENTITYOPERATIONCODE sy-vline
WA_ISTICKETITEMTP3_D_STR-ISACTIVEENTITY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.