Skip to Content

Case: Weighbridge scale sends the weight data to COMM Port.

Earlier we had to write a .NET program using SAP.NET Connector (Using VB.NET) and then from SAP side we had to create RFC so that the COMM port data gets utilized in SAP.

Now there is no need to use the third party software (VB.NET, C# etc) Using the following steps we can directly fetch the weight data at the COMM Port to SAP:

Step 1: Create a Function Module (code given below)

Step 2: Register the Windows activeX control MSCOM32.OCX on the client PC where the Weighbridge’s serial port is connected. Please click here to get detailed steps on how to register/activate this control.

Step 3: Implement this control in Transaction SOLE in SAP (Create an entry MSCOMMLIB.MSCOMM.1 and enter the CLSID.        {648A5600-2C6E-101B-82B6-000000000014}

Step 4: Active this MSCOMM32.OCX with Licence Key on the client PC where the Weighbridge’s serial port is connected.

Open RUN execute : regedit

Go to u201CHKEY_CLASSES_ROOT\Licenses\u201D

Create new key (Folder) name with ‘4250E830-6AC2-11cf-8ADB-00AA00C00905’

Give the default VALUE: kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun

Restart the system and run the FM. if the data is coming on the serial port then you will get the result.

FM Code:


FUNCTION z_serial_comport.
"-------------------------------------------------------------------------------"
""""Local Interface:
""  IMPORTING
""     REFERENCE(MODE) TYPE  I DEFAULT 0
""     REFERENCE(COMMPORT) TYPE  I DEFAULT 1
""     REFERENCE(SETTINGS) TYPE  C DEFAULT '2400,N,8,1'
""     REFERENCE(OUTPUT) TYPE  C OPTIONAL
""  EXPORTING
""     REFERENCE(INPUT) TYPE  C
""  EXCEPTIONS
""      NO_CREATE_OBJECT
"-------------------------------------------------------------------------------"
  TYPE-POOLS: sabc.
  INCLUDE ole2incl.
  PERFORM init.
  PERFORM open_port USING commport settings.
  IF mode = 0.
    PERFORM read_port
      CHANGING input.
  ENDIF.
  IF mode = 1.
    PERFORM write_port
      USING output
      CHANGING input.
  ENDIF.
  PERFORM final.
ENDFUNCTION.
DATA: o_obj TYPE ole2_object.
"-------------------------------------------------------------------------------"
FORM init.
  DATA:
    wa_repid LIKE sy-repid.
  wa_repid = sy-repid.
  CALL FUNCTION 'AUTHORITY_CHECK_OLE'
    EXPORTING
      program          = wa_repid
      activity         = sabc_act_call
      application      = 'MSCOMMLIB.MSCOMM.1'
    EXCEPTIONS
      no_authority     = 1
      activity_unknown = 2
      OTHERS           = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  CREATE OBJECT o_obj 'MSCOMMLib.MSComm.1'.
  IF sy-subrc <> 0.
    RAISE no_create_object.
  ENDIF.
ENDFORM.                    " Init
"-------------------------------------------------------------------------------"
FORM open_port USING commport settings.
  SET PROPERTY OF o_obj 'CommPort' = commport.
  SET PROPERTY OF o_obj 'Settings' = settings.
  SET PROPERTY OF o_obj 'InputLen' = 0.
  SET PROPERTY OF o_obj 'PortOpen' = 1.
ENDFORM.                   "open_port
"-------------------------------------------------------------------------------"
FORM read_port
  CHANGING input.
  DATA:
    wa_buffer TYPE i.
  DO 10 TIMES.
    GET PROPERTY OF o_obj 'InBufferCount' = wa_buffer.
    IF wa_buffer > 0.
      GET PROPERTY OF o_obj 'Input' = input.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.                    " read_port
"-------------------------------------------------------------------------------"
FORM write_port
      USING output
      CHANGING input.
  DATA:
    wa_buffer TYPE i.
  SET PROPERTY OF o_obj 'Output' = output.
  DO 10 TIMES.
    GET PROPERTY OF o_obj 'InBufferCount' = wa_buffer.
    IF wa_buffer > 0.
      GET PROPERTY OF o_obj 'Input' = input.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.                    "write_port
"-------------------------------------------------------------------------------"
FORM final.
  SET PROPERTY OF o_obj 'PortOpen' = 0.
  FREE OBJECT o_obj.
ENDFORM.                    " final

You may find additional help from the following links:

http://forums.sdn.sap.com/thread.jspa?threadID=1766170

http://www.sapfans.com/forums/viewtopic.php?f=13&t=145782&start=0&st=0&sk=t&sd=a

Regards,

Firoz.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. sarvesh rai

    Hi Firoz,

    I did all the activities as per your above Blog but I am facing below issue,

    In The program    SET PROPERTY OF o_obj ‘PortOpen’ = 1.I am getting sy-subrc = 3.

    I have all ports open. Firewall Off.

    I am using COMM1 port and passed following  parameters  9600,N,8,1.Please let me guide from here. Its very urgent.

    Thanks & Regards

    Sarvesh Rai

    (0) 
    1. Firoz Ashraf Post author

      Hi Sarvesh,

      Ideally after setting the property it should work. It could be due to authorization issue. Just login from admin account and check.

      Regards,

      Firoz.

      (0) 
    1. Firoz Ashraf Post author

      Hi Stefan,

      I believe you have solved this issue by converting the XSTRING to STRING using the CL_ABAP_CONV_IN_CE Class (as I can see this in your post).

      Cheers!

      (0) 

Leave a Reply